package com.cn.boot.student.service.rbac.impl;

import com.cn.boot.student.entity.UserRoleRelationEntity;
import com.cn.boot.student.mapper.UserRoleRelationMapper;
import com.cn.boot.student.service.rbac.IUserRoleRelationService;
import com.cn.boot.student.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户角色关系服务实现层
 */
@Service
@Transactional
//@CacheConfig(cacheNames = "urr")
public class UserRoleRelationServiceImpl implements IUserRoleRelationService {
    @Autowired
    private UserRoleRelationMapper userRoleRelationMapper;
    @Override
    public CommonResult add(UserRoleRelationEntity urr) {
        Integer result = userRoleRelationMapper.add(urr);
        if(result == 0){
            return CommonResult.failed("分配角色失败！！！");
        }
        return CommonResult.success("分配角色成功!!!");
    }

    @Override
    public CommonResult update(UserRoleRelationEntity urr) {
        Integer result = userRoleRelationMapper.update(urr);
        if(result == 0){
            return CommonResult.failed("更新失败！！！");
        }
        return CommonResult.success("更新成功!!!");
    }

    @Override
    public CommonResult del(Integer id) {
        Integer result = userRoleRelationMapper.del(id);
        if(result == 0){
            return CommonResult.failed("删除失败！！！");
        }
        return CommonResult.success("删除成功!!!");
    }

    @Override
    public CommonResult findAll() {
        List<UserRoleRelationEntity> list = userRoleRelationMapper.findAll();
        return CommonResult.success(list);
    }
}
